package com.song.JavaThread_day04.ch4_9;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class TaskMain {
	
	
	public static void main(String[] args) {
		
		ThreadPoolExecutor executor =(ThreadPoolExecutor)Executors.newCachedThreadPool();
		Task task = new Task();
		System.out.printf(" Main : Executing the task \n");
		Future<String> result = executor.submit(task);
		
		try {
			TimeUnit.SECONDS.sleep(2);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.printf("Main : Canceling the Task \n");
		result.cancel(true);
		
		System.out.printf("Main : Canceled the Task : %s \n" ,result.isCancelled());
		System.out.printf("Main : Done  the Task : %s\n" ,result.isDone());
		
		executor.shutdown();
		System.out.printf("Main : the executor has finish");
		
	}
}
